package com.travel.server.manager.impl.command.customer.data;

import com.travel.common.excel.ExcelData;
import com.travel.common.util.ExcelUtil;
import com.travel.server.manager.dto.request.customer.data.ExportCustomerDataRequest;
import com.travel.server.manager.dto.response.EmptyResponse;
import com.travel.server.manager.dto.response.customer.data.QueryCustomerDataResponse;
import com.travel.server.manager.impl.command.AbstractCommand;
import com.travel.server.manager.impl.sal.OrderDataSal;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author: LiZhenhui
 * @Date: 2018/12/10 16:21
 * @Desc:
 */
@Slf4j
@Component
public class ExportCustomerDataCommand extends AbstractCommand<ExportCustomerDataRequest, EmptyResponse> {

    @Autowired
    private QueryCustomerDataCommand queryCustomerDataCommand;

    @Override
    protected void checkInput(ExportCustomerDataRequest request) {

    }

    @Override
    public EmptyResponse handle(ExportCustomerDataRequest request) {
        QueryCustomerDataResponse response = queryCustomerDataCommand.handle(request);
        String compare = OrderDataSal.getCompare(request.getType());
        List<String> title = Arrays.asList("访客数", compare, "累计会员数", compare, "累计优质会员数", compare, "累计非会员数", compare, "成交客户数", compare);
        List<List<Object>> rows = new ArrayList<>();
        List<Object> objects = new ArrayList<>();
        objects.add(response.getVisit());
        objects.add(response.getVisitCompare());
        objects.add(response.getMember());
        objects.add(response.getMemberCompare());
        objects.add(response.getHighMember());
        objects.add(response.getHighMemberCompare());
        objects.add(response.getNotMember());
        objects.add(response.getNotMemberCompare());
        objects.add(response.getCustomer());
        objects.add(response.getCustomerCompare());
        rows.add(objects);
        ExcelData excelData = new ExcelData();
        excelData.setName("客户概况");
        excelData.setRows(rows);
        excelData.setTitles(title);
        ExcelUtil.exportExcel(getHttpServletResponse(), "客户概况", excelData);
        return new EmptyResponse();
    }
}
